package cn.lyjuan.payment.third.base.model.chl.service;

import cn.lyjuan.base.util.SpringContextHolder;
import cn.lyjuan.payment.third.base.common.enums.impl.ChlEnum;
import cn.lyjuan.payment.third.base.model.chl.check.AppChlCheck;
import cn.lyjuan.payment.third.base.model.chl.domain.AppChlModel;
import cn.lyjuan.payment.third.base.model.chl.domain.ChlCnfScanner;
import cn.lyjuan.payment.third.base.model.chl.domain.IChlCnfModel;
import org.springframework.stereotype.Component;

@Component
public class ChlService
{


    /**
     * 查询渠道信息
     *
     * @param appId
     * @param chlEnum
     * @return
     */
    public IChlCnfModel query(Integer appId, ChlEnum chlEnum)
    {
        AppChlModel chlModel = newInstance();

        boolean exist = chlModel.query(appId, chlEnum);
        if (!exist)
            return null;

        // 状态检查
        AppChlCheck.isvalid(chlModel.getEntity().getStatus());

        IChlCnfModel realModel = ChlCnfScanner.dispatch(chlEnum);
        realModel.query(appId);

        return realModel;
    }

    private AppChlModel newInstance()
    {
        return SpringContextHolder.getBean(AppChlModel.class);
    }
}
